package com.koron.css2.meterService.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.meterService.bean.MsReuseBean;
import com.koron.css2.meterService.mapper.MsReuseMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.ValidationKey;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 复表
 * @author 周利斌
 *
 */
public class MsReuseBackfill implements ServerInterface{
	
	private static Logger log = LogManager.getLogger(MsReuseBackfill.class);

	@Override
    @ValidationKey(clazz = MsReuseBean.class,method = "insert")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<Void> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "保存成功", Void.class);
		try {
			MsReuseBean bean = JsonUtils.objectToPojo(req.getData(), MsReuseBean.class);
			if(StringUtils.isBlank(bean.getId())) {
				return MessageBean.create(Constant.MESSAGE_DBFAIL, "保存失败", Void.class);
			}
			MsReuseMapper mapper = factory.getMapper(MsReuseMapper.class);
			int iCount = mapper.updateMsReuse(bean);
			if(iCount < 1) {
				info.setCode(Constant.MESSAGE_INT_FAIL);
				info.setDescription("保存失败");
			}
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("保存失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}

}
